package top.hekun.study.core.visitor.complex;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.commons.SimpleRemapper;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import top.hekun.study.core.model.HelloWord;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 复杂的类修改示例
 * 〈 合并 类的方法和字段〉
 *
 * @author: Sakura
 * @date: 2023/5/16
 */
public class MyClassVisitor2 extends ClassVisitor {
         private  ClassNode classNode;

    public MyClassVisitor2(int apiVersion, ClassVisitor classWriter,ClassNode classNode) {
        super(apiVersion, classWriter);
        this.classNode=classNode;
    }
    @Override
    public void visitEnd() {
        List<FieldNode> fields = classNode.fields;
        for (FieldNode fn : fields) {
            fn.accept(this);
        }

        List<MethodNode> methods = classNode.methods;
        for (MethodNode mn : methods) {
            String methodName = mn.name;
            if ("<init>".equals(methodName)) {
                continue;
            }
            mn.accept(this);
        }
        super.visitEnd();
    }

}
